package cz.cuni.amis.episodic.lisp.visitor;

import cz.cuni.amis.episodic.lisp.behan.Visitor;
import cz.cuni.amis.episodic.lisp.behan.VisitableTree;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


public abstract class TreeTraceVisitor implements Visitor<ArrayList<String>> {
  	    
    
	LinkedList<List<String>> trace = new LinkedList<>();

	@Override
	public Visitor<ArrayList<String>> visitTree(
			VisitableTree<ArrayList<String>> tree) {
		return this;
	}

	@Override
	public boolean visitData(VisitableTree<ArrayList<String>> parent,
			ArrayList<String> data, boolean isLeaf) throws IOException {

		if (isLeaf) {
			List<List<String>> copy = new ArrayList<>(trace);
			copy.add(data);
			traceVisited(copy);
			
		} else {
			trace.add(data);
		}
		return true;
	}
	
	public abstract void traceVisited(List<List<String>> trace);


	@Override
	public boolean postVisitData(
			VisitableTree<ArrayList<String>> parent,
			ArrayList<String> data, boolean isLeaf) throws IOException {
		// TODO Auto-generated method stub
		trace.removeLast();
		return true;
	}
}
